<?php

Frodo::import("com.utils.ArrayObj");
Frodo::import("com.utils.HashMap");
Frodo::import("com.events.Event");
Frodo::import("com.events.EventListener");

class EventDispatcher{
	/**
	 * Enter description here...
	 *
	 * @var HashMap
	 */
	private $_listeners;
	
	public function __construct(){
		$this->_listeners = new HashMap();
	}
	
	public function addEventListener($type,$listener){
		if ($this->_listeners->containsKey($type)) {
			$this->_listeners->find($type)->push($listener);
		}else{
			$array = new ArrayObj(array());
			$array->push($listener);
			$this->_listeners->insert($type,$array);
		}
	}
	
	public function dispatchEvent(Event $event){
		if ($this->_listeners->containsKey($event->getType())) {
			$iterator = $this->_listeners->find($event->getType())->iterator();
			while ($iterator->hasNext()) {
				$iterator->next()->listen($event);
			}
		}
	}
	
	
}

?>